package TwoSeach;

import org.junit.Test;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: TwoSeach
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-11-04  11:27
 * @Description: TODO
 * @Version: 1.0
 */
public class X的平方根69 {


    public int mySqrt(int x) {
        int left = 0, right = x, ans = -1;
        while (left <= right) {
            int mid = (left + right) >> 1;
            long suqare = (long) mid * mid;
            if (suqare <= x) {
                ans = mid;
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return ans;
    }

    @Test
    public void test() {
        int i = mySqrt(2147395599);
        System.out.println(i);
    }
}
